home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / common / server / missionDownload.cs < prev    next >
Text File  |  2005-11-23  |  4KB  |  118 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // Mission Loading
  8. // The server portion of the client/server mission loading process
  9. //-----------------------------------------------------------------------------
  10.  
  11. //--------------------------------------------------------------------------
  12. // Loading Phases:
  13. // Phase 1: Transmit Datablocks
  14. //          Transmit targets
  15. // Phase 2: Transmit Ghost Objects
  16. // Phase 3: Start Game
  17. //
  18. // The server invokes the client MissionStartPhase[1-3] function to request
  19. // permission to start each phase.  When a client is ready for a phase,
  20. // it responds with MissionStartPhase[1-3]Ack.
  21.  
  22. function GameConnection::loadMission(%this)
  23. {
  24.    // Send over the information that will display the server info
  25.    // when we learn it got there, we'll send the data blocks
  26.    %this.currentPhase = 0;
  27.    if (%this.isAIControlled())
  28.    {
  29.       // Cut to the chase...
  30.       %this.onClientEnterGame();
  31.    }
  32.    else
  33.    {
  34.       commandToClient(%this, 'MissionStartPhase1', $missionSequence,
  35.          $Server::MissionFile, MissionGroup.musicTrack);
  36.       echo("*** Sending mission load to client: " @ $Server::MissionFile);
  37.    }
  38. }
  39.  
  40. function serverCmdMissionStartPhase1Ack(%client, %seq)
  41. {
  42.    // Make sure to ignore calls from a previous mission load
  43.    if (%seq != $missionSequence || !$MissionRunning)
  44.       return;
  45.    if (%client.currentPhase != 0)
  46.       return;
  47.    %client.currentPhase = 1;
  48.  
  49.    // Start with the CRC
  50.    %client.setMissionCRC( $missionCRC );
  51.  
  52.    // Send over the datablocks...
  53.    // OnDataBlocksDone will get called when have confirmation
  54.    // that they've all been received.
  55.    %client.transmitDataBlocks($missionSequence);
  56. }
  57.  
  58. function GameConnection::onDataBlocksDone( %this, %missionSequence )
  59. {
  60.    // Make sure to ignore calls from a previous mission load
  61.    if (%missionSequence != $missionSequence)
  62.       return;
  63.    if (%this.currentPhase != 1)
  64.       return;
  65.    %this.currentPhase = 1.5;
  66.  
  67.    // On to the next phase
  68.    commandToClient(%this, 'MissionStartPhase2', $missionSequence, $Server::MissionFile);
  69. }
  70.  
  71. function serverCmdMissionStartPhase2Ack(%client, %seq)
  72. {
  73.    // Make sure to ignore calls from a previous mission load
  74.    if (%seq != $missionSequence || !$MissionRunning)
  75.       return;
  76.    if (%client.currentPhase != 1.5)
  77.       return;
  78.    %client.currentPhase = 2;
  79.  
  80.    // Update mod paths, this needs to get there before the objects.
  81.    %client.transmitPaths();
  82.  
  83.    // Start ghosting objects to the client
  84.    %client.activateGhosting();
  85.    
  86. }
  87.  
  88. function GameConnection::clientWantsGhostAlwaysRetry(%client)
  89. {
  90.    if($MissionRunning)
  91.       %client.activateGhosting();
  92. }
  93.  
  94. function GameConnection::onGhostAlwaysFailed(%client)
  95. {
  96.  
  97. }
  98.  
  99. function GameConnection::onGhostAlwaysObjectsReceived(%client)
  100. {
  101.    // Ready for next phase.
  102.    commandToClient(%client, 'MissionStartPhase3', $missionSequence, $Server::MissionFile);
  103. }
  104.  
  105. function serverCmdMissionStartPhase3Ack(%client, %seq)
  106. {
  107.    // Make sure to ignore calls from a previous mission load
  108.    if(%seq != $missionSequence || !$MissionRunning)
  109.       return;
  110.    if(%client.currentPhase != 2)
  111.       return;
  112.    %client.currentPhase = 3;
  113.  
  114.    // Server is ready to drop into the game
  115.    %client.startMission();
  116.    %client.onClientEnterGame();
  117. }
  118.